import os
from time import sleep

import yaml
from faker import Faker


def mock_user_date():
    data_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data', 'user_date.yml')
    faker = Faker(locale="zh_CN")

    data = {}
    user_list = []
    ids_list = []
    for i in range(3):
        name = faker.name()
        phone_number = faker.phone_number()
        user_list.append({"name": name, "phone_number": phone_number})
        ids_list.append(name)
    data["user_info"] = user_list
    data["ids"] = ids_list

    with open(data_path, 'w', encoding="utf-8") as f:
        yaml.safe_dump(data, f)


def user_date():
    sleep(2)
    user_date_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data", "user_date.yml")
    with open(user_date_path, 'r', encoding='utf-8') as f:
        date = yaml.safe_load(f)
        print(date)
    return date


if __name__ == "__main__":
    mock_user_date()
